@extends('app')
@include('UEditor::head')
@section('content')
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak={{$baidukey}}"></script>
<ul class="nav nav-tabs">
    <li><a href="{{ url('/admin/enterprise/companys')}}">信息列表</a></li>
    <li class="active"><a href="#">信息编辑</a></li>
</ul>
<form id="companyForm" method="post">
    <div class="panel panel-default description2 mt20">
        <div class="form-group">
            <div class="col-sm-2 control-label">企业名称:</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="name" id="name" placeholder="企业名称" value="@if(!empty($result)){{ $result->name }}@endif">
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">企业签名:</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="signature" id="signature" placeholder="企业签名" value="@if(!empty($result)){{ $result->signature }}@endif">
            </div>
            <div class="clearfix"></div>
        </div>
         <div class="form-group">
            <div class="col-sm-2 control-label">企业LOGO:</div>
            <div class="col-sm-10">
                <input id="uploadimg" name="uploadimg" type="file" multiple="true">
                <div id="imgbox" class="dustbin">
                    <div style='width:90px; height:60px;float:left;'>
                        <img width='90' height='60' src='@if(!empty($result)){{$result->logo}}@endif'  />
                        <input type='hidden' name='logo' value='@if(!empty($result)){{$result->logo}}@endif' />
                    </div>
                </div>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">行业分类:</div>
            <div class="col-sm-10 clearfix">
                @foreach($types as $tp)
                <label class="fl" style="margin-left:10px;">
                    <input type="checkbox" name="ctype[]" value="{{$tp->id}}" @if(!empty($result) && count($result->types)>0) @if(in_array($tp->id,$result->comtype)) checked @endif  @endif >{{$tp->name}}
                </label>
                @endforeach
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">企业介绍:</div>
            <div class="col-sm-10">
                <script id="intro" name="intro"  style="width:100%;margin:0 auto;height:200px;" type="text/plain">
                </script>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">企业邮箱:</div>
            <div class="col-sm-10">
                <input type="email" class="form-control" name="email" id="email" placeholder="企业邮箱" value="@if(!empty($result)){{ $result->email }}@endif">
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">企业电话:</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="phone" id="phone" placeholder="企业电话" value="@if(!empty($result)){{ $result->phone }}@endif">
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">企业性质:</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="nature" id="nature" placeholder="企业性质：私营、股份制、事业单位" value="@if(!empty($result)){{ $result->nature }}@endif">
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">企业主页:</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="main_page" id="main_page" placeholder="企业主页" value="@if(!empty($result)){{ $result->main_page }}@endif">
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">企业发展阶段:</div>
            <div class="col-sm-10">
                <select name="develop" class="form-control">
                    @foreach($develops as $dev)
                    <option value="{{ $dev->id }}" @if(!empty($result)) @if($result->develop_id == $dev->id ) selected @endif @endif>{{ $dev->name }}</option>
                    @endforeach
                </select>
            </div>
            <div class="clearfix"></div>
        </div>
         <div class="form-group">
            <div class="col-sm-2 control-label">投资机构:</div>
            <div class="col-sm-10">
                <textarea  class="form-control" name="investment" rows="5">@if(!empty($result)){{ $result->investment }}@endif</textarea>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">企业规模:</div>
            <div class="col-sm-10">
                <select name="scale" class="form-control">
                    @foreach($scales as $scale)
                    <option value="{{ $scale->id }}" @if(!empty($result)) @if($result->scale_id == $scale->id ) selected @endif @endif>{{ $scale->name }}</option>
                    @endforeach
                </select>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">认证类型:</div>
            <div class="col-sm-10">
                <select name="authtype" class="form-control">
                    @foreach($authes as $ath)
                    <option value="{{ $ath->auth_id }}" @if(!empty($result)) @if($result->auth_id == $ath->id ) selected @endif @endif>{{ $ath->name }}</option>
                    @endforeach
                </select>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">相关标签:</div>
                <div class="col-sm-10 col-xs-12">
                    <div class="tagsinput-primary">
                        <input name="tagsinput" class="tagsinput" data-role="tagsinput" value="@if(!empty($newstag)) {{ $newstag }} @endif" />
                    </div>
                </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">传真:</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="tel" id="tel" placeholder="传真" value="@if(!empty($result)){{ $result->tel }}@endif">
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">邮编:</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="zip_code" id="zip_code" placeholder="邮编" value="@if(!empty($result)){{ $result->zip_code }}@endif">
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">公交路线:</div>
            <div class="col-sm-10">
                <input type="text" class="form-control" name="bus_route" id="bus_route" placeholder="公交路线" value="@if(!empty($result)){{ $result->bus_route }}@endif">
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2 control-label">企业地址:</div>
            <div class="col-sm-2">
                <select class="form-control" onchange="childAreas(this.value,'areas','city')" name="province" id="province">
                    <option>---选择省份---</option>
                    @foreach($area as $are)
                    <option value="{{$are->area_id}}" @if(!empty($result)) @if($address->province == $are->area_id) selected @endif @endif>{{$are->title}}</option>
                    @endforeach
                </select>
            </div>
            <div class="col-sm-2">
                <select class="form-control" onchange="childAreas(this.value,'areas','area')" name="city" id="city">
                    <option>---选择市---</option>
                    @if($blademode == 'edit')
                    @foreach($subarea as $subare)
                    <option value="{{$subare->area_id}}" @if(!empty($result)) @if($address->city == $subare->area_id) selected @endif @endif>{{$subare->title}}</option>
                    @endforeach
                    @endif
                </select>
            </div>
            <div class="col-sm-2">
                <select class="form-control" name="area" id="area">
                    <option>---选择地区---</option>
                    @if($blademode == 'edit' || (!empty($result) && ($address->area == 0)))
                    @foreach($thrarea as $thrare)
                    <option value="{{$thrare->area_id}}" @if(!empty($result)) @if($address->area == $thrare->area_id) selected @endif @endif>{{$thrare->title}}</option>
                    @endforeach
                    @endif
                </select>
            </div>
            <div class="col-sm-4">
                <input type="text" class="form-control" name="address" id="address" placeholder="详细地址" value="@if(!empty($address)){{ $address->address }}@endif"">
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2"></div>
            <div class="col-sm-2">
                <input type="button" class="form-control" onClick="getPoint()" value="获取坐标">
            </div>
            <div class="col-sm-4">
                <input type="text" class="form-control" name="longitude" id="PointLng" placeholder="经度" value="@if(!empty($address)){{ $address->longitude }}@endif">
            </div>
            <div class="col-sm-4">
                <input type="text" class="form-control" name="latitude" id="PointLat" placeholder="纬度" value="@if(!empty($address)){{ $address->latitude }}@endif">
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
            <div class="col-sm-2"></div>
            <div class="col-sm-10">
                <div id="allmap" style="width:100%;height:380px;border:1px solid #bcbcbc;"></div>
                <script type="text/javascript">
                    $(function(){
                        bdmap();
                    });
                    function bdmap(){
                       var blademode = $("#blademode").val();
                       var map = new BMap.Map("allmap"); // 创建Map实例
                       if( blademode == 'add'){
                           map.centerAndZoom("南京",11);      // 初始化地图,用城市名设置地图中心点
                       }else{
                          var lng = $("#PointLng").val();
                          var lat = $("#PointLat").val();
                          if( lng != "" && lat != ""){
                               map.clearOverlays();
                               var point = new BMap.Point(lng,lat);
                               map.centerAndZoom(point, 18);
                               var marker = new BMap.Marker(point);  // 创建标注
                               map.addOverlay(marker);                // 将标注添加到地图中
                          }else{
                              var p = $('#province  option:selected').text();
                              var c = $('#city  option:selected').text();
//                              var a = $('#area  option:selected').text();
                              var add = $("#address").val();
                              var address = p + c + add;
                               // 创建地址解析器实例
                               var myGeo = new BMap.Geocoder();
                               // 将地址解析结果显示在地图上,并调整地图视野
                               myGeo.getPoint(address, function(point){
                                   if (point) {
                                       map.centerAndZoom(point, 18);
                                       var marker = new BMap.Marker(point);  // 创建标注
                                       map.addOverlay(marker);              // 将标注添加到地图中
                                   }else{
                                       alert("您选择地址没有解析到结果!");
                                   }
                               }, "");
                          }
                       }
                        map.enableScrollWheelZoom();
                        map.enableContinuousZoom();
                        map.addControl(new BMap.NavigationControl());   // 添加平移缩放控件
                        map.addControl(new BMap.ScaleControl());        // 添加比例尺控件
                        map.addControl(new BMap.OverviewMapControl());  //添加缩略地图控件
                        map.addEventListener("click",function(e){       //鼠标单击事件
                            document.getElementById("PointLng").value = e.point.lng;
                            document.getElementById("PointLat").value = e.point.lat;
                        });
                    }
                    function getPoint(){
                        var p = $('#province  option:selected').text();
                        var c = $('#city  option:selected').text();
//                        var a = $('#area  option:selected').text();
                        var add = $("#address").val();
                        var address = p + c + add;
                        var map = new BMap.Map("allmap");
                        var local = new BMap.LocalSearch(map, {
                            renderOptions:{map: map}
                        });
                        local.search(address);
                        map.addEventListener("click",function(e){
                            document.getElementById("PointLng").value = e.point.lng;
                            document.getElementById("PointLat").value = e.point.lat;
                        });
                    }
                </script>
            </div>
            <div class="clearfix"></div>
        </div>
        <div class="form-group">
             <div class="col-sm-2 control-label">相关账户:</div>
             <div class="col-sm-10">
                @if(!empty($result))
                @foreach($result->users as $cuser)
                <a href="">{{$cuser->name}}</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                @endforeach
                @endif
             </div>
             <div class="clearfix"></div>
        </div>
        <input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
        {!! csrf_field() !!}
        <input type="hidden" name="company_id" value="@if(!empty($result)){{ $result->id }}@endif">
        <input type="hidden" name="add_id" value="@if(!empty($address)){{ $address->add_id }}@endif">
        <input type="hidden" name="blademode" id="blademode"  value="{{ $blademode }}">
        <div class="form-inline">
            <div class="form-group col-xs-offset-1">
                <button type="button" class="btn btn-info" onclick="saveData('/admin/enterprise/companys','companyForm')">
                    <i class="icon-ok bigger-110"></i>
                        Submit
                </button>
            </div>
            <div class="form-group col-xs-offset-1">
                <button type="reset" class="btn">
                    <i class="icon-undo bigger-110"></i>
                    Reset
                </button>
            </div>
        </div>
    </div>
</form>


<script type="text/javascript">
<!--
var ue = UE.getEditor('intro');
ue.ready(function() {
	var introduction = '@if(!empty($result)) {!! str_replace(array("\r\n", "\r", "\n"),"",str_replace("'",'"',$result->intro))!!} @endif';
	ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');//此处为支持laravel5 csrf ,根据实际情况修改,目的就是设置 _token 值. 
	ue.setContent(introduction);   
});

$(function(){
    $('input').iCheck({
    	checkboxClass: 'icheckbox_flat-blue',
        radioClass: 'iradio_flat-blue',
        increaseArea: '-10' // optional
    });
	/***图片上传****/
	$("#uploadimg").uploadify({
	    'formData'     : {
	        'fileField':'upfile',
	        '_token':'{{ csrf_token() }}',
	        'type':'companylogo'
	    },
	    "width"           : 120,
	    "height"          : 30,
	    "queueSizeLimit"  :1,
	    "swf"             : "{{ asset('/js/uploadify/uploadify.swf') }}",
	    "fileObjName"     : "upfile",
	    "buttonText"      : "上传图片",
	    "uploader"        : '/admin/upload/newsimage',
	    'removeTimeout'	  : 1,
	    'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
	    'onUploadSuccess':function(file, data, response){
	    	var data = eval('(' + data + ')');
	        if (data.status == 'success') {

	        	var html="<div style='width:90px; height:60px;float:left;'>"
	            			+"<img width='90' height='60' src='"+data.url+"'  /><input type='hidden' name='logo' value='"+data.url+"' />"
	            			+"</div>"
	            $('#imgbox').html(html);
	        }else{
	            alert(data.msg);
	            return false;
	        }

	    }

	});
});
//-->
</script>
@endsection
